package com.example.controller;

import com.example.pojo.PageBean;
import com.example.pojo.Payment;
import com.example.pojo.Result;
import com.example.service.PayService;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private PayService payService;

    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                         String customername, String paymentstatus, String productName, String status,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin1, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end1) {
        PageBean pageBean = payService.page(page, pageSize,customername,paymentstatus,productName, status ,begin, end,begin1,end1);
        return Result.success(pageBean);
    }
    @GetMapping("/page1")
    public Result page1(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                       String customername, String paymentstatus, String productName, String status,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin1, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end1) {
        PageBean pageBean = payService.page1(page, pageSize,customername,paymentstatus,productName, status ,begin, end,begin1,end1);
        return Result.success(pageBean);
    }
    @GetMapping("/page2")
    public Result page2(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                        String customername, String paymentstatus, String productName, String status,
                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin1, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end1) {
        PageBean pageBean = payService.page2(page, pageSize,customername,paymentstatus,productName, status ,begin, end,begin1,end1);
        return Result.success(pageBean);
    }
    @GetMapping("/ss")
    public Result page2s(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
        PageBean pageBean = payService.page2s(page, pageSize,date);
        return Result.success(pageBean);
    }

    @PostMapping
    public Result add(@RequestBody Payment payment){
        payService.add(payment);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deletes(@PathVariable int [] id){
        payService.delete(id);
        return Result.success();
    }
    @PostMapping("/check")
    public Result check(@RequestBody Payment payment){
       String ma= payService.check(payment);
        return Result.success(ma);
    }
    @PostMapping("/chuku")
    public Result chuku(@RequestBody Payment payment){
        payService.chu(payment);
        return Result.success();
    }

    @GetMapping("/get")
    public Result getAll(){
        return Result.success(payService.getAll());
    }
}
